<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // function User(){
        //    let name="",age="";
        //     this.setImg=function(name,age){
        //         this.name=name;
        //         this.age=age;
        //     };
        //     this.getImg=function(){
        //         return `姓名:${this.name},年龄:${this.age}`;
        //     };
        // }
        // let user1=new User();
        // user1.setImg("唐玮",25)
        // console.log(user1.getImg());

        //上面的定义变量可以省略
//         function User(name,age){
//             this.name=name;
//             this.age=age;
//             this.getImg=function(){
//                 return `${this.name}:${this.age} `
               
//             };
//         }

//        let user1= new User("唐玮",25);
// console.log(user1.getImg()); 



//怎么让对象的属性在外边访问不到，自己在里面自己进行，把属性封装起来

function User(name,age){
    let data={name:name,age:age};//属性私有化
    this.show=function(){
        console.log(`${data.name}:${data.age}岁`);
    };

}

let user=new User("唐玮",22);
//在data里面的属性不能修改和访问到
user.show();
   </script>
</body>
</html>